from genutils.special_functions import alpha

class Alpha_synapse():
    """ class used to simulate an alpha function conductance change. 
        alpha function:
            gmax * (t-onset)/tau * exp(-(t - onset - tau)/tau)
        when called will return:
            I_synapse = g(t) * (V - E_rev) 
                where g(t) is the alpha function above. 
        Units:
            returns --> current in nA. """
    def __init__(self,onset=1,tau=1,gmax=1,E_rev=0):
        """ Units:
                onset --> ms
                tau   --> ms
                gmax  --> uS
                E_rev --> mV  """
        self.onset = onset
        self.tau   = tau
        self.gmax  = gmax
        self.E_rev = E_rev
        
    def __call__(self,sv,t):
        """ requires a state variable dictionary and time to be passed.
            returns the current passing through the cell membrane due to this
            synapse in nA. """
        return alpha(self.onset,self.tau,self.gmax,t) * (self.E_rev - sv['V'])
